package com.conexion;

import java.io.InputStream;
import java.util.List;
import org.apache.http.NameValuePair;


import android.app.ProgressDialog;
import android.util.Log;

public class HiloConexion extends Thread{
	public Syncronizar sync;
	private String resultadoConexion = "";
	private boolean bandera=false;
	ProgressDialog pd;
	private List<NameValuePair> params;
	public String route;
	
	public String conexion = "http://www.mactel.com.pe/CM/";
	
	public HiloConexion(){}
	
	public HiloConexion(Syncronizar syn, List<NameValuePair> param, String route){
		this.sync=syn;
		this.params=param;
		this.route=route;
		Log.d("TAG","LLEGA TERCERO AKI");
	    pd = ProgressDialog.show(syn.getWindow(), "Conectando...", "Conectando con el servidor");
	}
		
	public void run(){
		InputStream is = null;
		String result = ""; 

		try{		       
			WBhelper helper = new WBhelper(conexion+"camara_controller/");
			String responseBody=helper.obtainResponse(this.route,this.params);			
			
			Log.e("log_tag", responseBody );
			if (responseBody!="error"){
				
				this.sync.setResponse(responseBody);
			}else{
				Log.e("log_tag", "Error in webservice");
			     pd.dismiss();
			     bandera=false;
			}				
		}catch(Exception e){
		     Log.e("log_tag", "Error in http connection "+e.toString());
		     pd.dismiss();
		     bandera=false;
		}
		bandera=true;
		pd.dismiss();
	}


}
